/*
EP3D is a real-time 3D planet engine , which in addition to providing 
substandard scene rendering and scene management, of course, it also 
provides some basic class libraries to build the entire virtual 
planet, or even the entire universe.

Copyright (C) 2010  Hongjiang Zhang	(zhjwyat@gmail.com)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef EP3D_COLOR_H
#define EP3D_COLOR_H

#include "EP3DBase.h"
#include "EP3DVector2.h"

//Start of EP3D namespace section
namespace EP3D
{
typedef uint32 argb;				//!< 32 bit ARGB representation of a Color

//Defines macro to represent Color
#ifndef COLOR_ARGB
#define COLOR_ARGB(a, r, g ,b) \
	((argb)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff)))
#endif

//begin of class 
class EP3DEXPORT Color
{
public:
	/************************************************************************/
	/*	Construction                                                                 
	/************************************************************************/
	Color(void);
	Color(const Color& val);
	Color(const f32* pf);
	Color(f32 red, f32 green, f32 blue, f32 alpha = 1.0f);
	Color(argb& val);

	/************************************************************************/
	/*   Accessors         
	/************************************************************************/
	f32	GetAlpha(void) const		{return a;}
	f32	GetRed(void) const			{return r;}
	f32	GetGreen(void) const		{return g;}
	f32	GetBlue(void) const			{return b;}

	/************************************************************************/
	/*   casting
	/************************************************************************/
	inline operator argb() const;
	inline operator f32* () const;

	/************************************************************************/
	/*	 assignment operators                                                           
	/************************************************************************/
	inline Color& operator += (const Color& val);
	inline Color& operator -= (const Color& val);
	inline Color& operator *= (const f32 f);
	inline Color& operator /= (const f32 f);

	/************************************************************************/
	/*	unary operators
	/************************************************************************/
	inline Color operator + () const;
	inline Color operator - () const;

	/************************************************************************/
	/*	binary operators                                                                     
	/************************************************************************/
	inline Color operator + (const Color& val) const;
	inline Color operator - (const Color& val) const;
	inline Color operator * (const f32 f) const;
	inline Color operator / (const f32 f) const;

	EP3DEXPORT friend Color operator * (const f32 f, const Color& val);
	static Color* ColorLerp(Color* pOut, const Color* val1, const Color* val2, const f32 f);

	inline bool operator == (const Color& val) const;
	inline bool operator != (const Color& val) const;

public:
	/************************************************************************/
	/*	Implementation Data                                                                   
	/************************************************************************/
	f32 a, r, g, b;
};


class EP3DEXPORT ColorRect
{
public:
	ColorRect();
	ColorRect(const Color& color);
	ColorRect(const Color& tl, const Color& tr, const Color& bl, const Color& br);

	void SetAlpha(f32 alpha);

	void SetLeftAlpha(f32 alpha);
	
	void SetTopAlpha(f32 alpha);
	
	void SetRightAlpha(f32 alpha);

	void SetBottomAlpha(f32 alpha);

	bool IsMonochromatic() const;

	ColorRect GetSubRectangle(f32 left, f32 top, f32 right, f32 bottom);

	Color GetColorAtPoint(Point point);

	void SetColor(const Color& color);

public:
	//Implementation Data
	Color topleft, topright, bottomleft, bottomright;
};

}//End of EP3D namespace section
#endif
